//       https://www.nowcoder.com/practice/562630ca90ac40ce89443c91060574c6




#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];

    sort(a.begin(), a.end());
    int l = 0, r = 1, ans = 1;
    for (; r < n; r++)
    {
        while (a[r] - a[l] > k)
            l++;
        ans = max(ans, r - l + 1);
    }

    cout << ans << endl;
    return 0;
}